<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card>
      <div class="table-operator">
        <a-button
          v-btnPermission="'hse_004_add_01'"
          type="primary"
          icon="plus"
          @click="handleUpdate('add', {})"
        >
          新增辨识会议
        </a-button>
      </div>
      <s-table
        ref="table"
        size="default"
        row-key="key"
        :columns="columns"
        :data="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <span
          slot="sort"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="operation"
          slot-scope="text, record"
        >
          <a
            v-if="record.status == 20"
            v-btnPermission="'hse_004_edi_02'"
            @click="handleUpdate('start', record)"
          >查看会议</a>
          <!-- <a-divider v-if="record.status == '30'" type="vertical" /> -->
          <a
            v-if="record.status == 30 || record.status == 50"
            v-btnPermission="'hse_004_edi_02'"
            @click="handleUpdate('edit', record)"
          >进入会议</a>
          <a
            v-if="record.status == 40 || record.status == 35"
            v-btnPermission="'hse_004_loo_03'"
            @click="handleUpdate('look', record)"
          >查看会议</a>
          <!-- <a-divider v-if="record.auditStatus == 'DRAFT'" type="vertical" /> -->
          <!-- <a @click="handleUpdate('del', record)" v-if="record.auditStatus == 'DRAFT'">删除</a> -->
          <span
            v-if="record.meetingTypeCategory == '3' && record.status != 20 && record.status != 30"
            v-btnPermission="'hse_004_moi_04'"
          >
            <a-divider type="vertical" />
            <approval-button
              :id="record.id"
              :status="record.status == 35 ? 'SUBMITTED' : 'REJECTED'"
            />
          </span>
        </span>
        <span
          slot="hsemonth"
          slot-scope="text, record"
        >
          {{ record.meetingExtraVO.hsemonth }}
        </span>
        <span
          slot="status"
          slot-scope="text, record"
        >
          <list-status
            :status="record.status"
            conversion="en"
            :text="text"
          />
        </span>
      </s-table>
    </a-card>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { STable } from '@/components'
import listStatus from '@/components/list_status/meeting_status'
import { getMeetingList, startMeeting } from '@/api/office/conference'

const columns = [
    {
        title: '序号',
        dataIndex: 'sort',
        scopedSlots: { customRender: 'sort' },
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        dataIndex: 'projectName',
    },
    {
        title: '会议月份',
        dataIndex: 'hsemonth',
        scopedSlots: { customRender: 'hsemonth' },
    },
    {
        title: '主持人',
        dataIndex: 'speaker',
    },
    {
        title: '会议名称',
        dataIndex: 'meetingName',
    },
    {
        title: '参会人数',
        dataIndex: 'meetingCount',
    },
    {
        title: '创建人',
        dataIndex: 'creatorName',
    },
    // {
    //     title: '提交时间',
    //     dataIndex: 'startTime',
    // },
    {
        title: '状态',
        dataIndex: 'status',
        scopedSlots: { customRender: 'status' },
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        fixed:'right',
        scopedSlots: { customRender: 'operation' },
    },
]
const searchArr = [
    // {
    //     name: '所属分公司',
    //     valueKey: 'branchComId',
    //     type: SelectSubCompany,
    // },
    {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
    // {
    //     name: '所属项目',
    //     keyValue: 'branchComId',
    //     valueKey: 'projectId',
    //     type: SelectProject,
    // },
    {
        name: '会议名称',
        value: 'meetingName',
        type: 'input',
    },
    {
        name: '召开时间',
        value: 'startEndDate',
        type: 'dateRange',
    },
    {
        name: '会议月份',
        value: 'month',
        type: 'month',
    },
    {
        name: '状态',
        value: 'status',
        type: 'select',
        data: [
            {
                value: '20',
                label: '待开始',
            },
            {
                value: '30',
                label: '进行中',
            },
            {
                value: '35',
                label: '审核中',
            },
            {
                value: '40',
                label: '已完结',
            },
            {
                value: '50',
                label: '审核不通过',
            },
        ],
    },
]
export default {
    name:'a'+Date.now(),    components: {
        STable,
        listStatus,
    },
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            loadData: async (parameter) => {
                this.queryParam.query = { ...this.queryParam.query, typeId: 3 }
                const requestParameters = Object.assign({}, parameter, this.queryParam)
                const [err, res] = await getMeetingList(requestParameters)
                return new Promise((resolve, reject) => {
                    if (err) {
                        reject(err)
                    } else {
                        resolve(res)
                    }
                })
            },
        }
    },
    methods: {
        //搜索
        search(val = {}) {
            this.queryParam.query = {
                ...val,
                typeId: 3,
                hsemonth: (val.month && val.month.format('YYYY-MM')) || void 0,
                startTime: (val.applyTime && val.applyTime.length && val.applyTime[0].format('YYYY-MM-DD')) || void 0,
                endTime: (val.applyTime && val.applyTime.length && val.applyTime[1].format('YYYY-MM-DD')) || void 0,
            }
            console.log(this.queryParam)
            delete this.queryParam.query.month
            this.$refs.table.refresh(true)
        },

        // 处理更新操作（新增、编辑）
        async handleUpdate(type, data = {}) {
            if (type == 'del') {
                // const [err, res] = await deleteEquipment({ id: data.id })
                // if (!err) {
                //     this.$message.success('成功')
                //     this.$refs.table.refresh(true)
                // }
            }
            // else if (type == 'start') {
            //     const [err, res] = await startMeeting({ id: data.id })
            //     if (!err) {
            //         this.$message.success('成功')
            //         this.$refs.table.refresh(true)
            //     }
            // }
            else if (type == 'edit' || type == 'look' || type == 'start') {
                this.$router.push({
                    name: 'safetyInMeeting',
                    query: {
                        id: data.id || '',
                        pageType: type,
                    },
                })
            } else {
                this.$router.push({
                    name: 'safetyAddConference',
                    query: {
                        id: data.id || '',
                        pageType: type,
                        typeId: 3,
                    },
                })
            }
        },
    },
}
</script>
